package cn.gxufe.reliable.message.api.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.ResultSet;

/**
 * @author yingjie.rong
 **/
public abstract class BaseTryService {

    public final String sql = "select status from reliable_message where `key` = ? ";

    @Autowired
    private JdbcTemplate jdbcTemplate;

    protected int getStatus(Long messageId, String key, String header,String prefix){
        return jdbcTemplate.query(sql, new Object[]{ prefix +  key }, (ResultSet rs) -> {
                    if (rs.next()) {
                        return rs.getInt(1);
                    }else{
                        return -1;
                    }
                }
        );
    }
}
